<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="../css/page/login.css" />
</head>

<body>
    <div class="reglogo  " style="height: 100px; margin-top: 30px; text-align: center;">
        <img  src="../images/logo.png" />
    </div>
    <div class="row">
        <input id="username" class="input" type="text" placeholder="手机号">
    </div>
    <div class="row">
        <input id="password" class="input" type="password" placeholder="密码">
    </div>
    <div class="row login-info" style="border-bottom:0px ;">
        <input type="checkbox" id="agree" />
        <div>我已经阅并同意本APP的<span class="key-link" onclick="core.news(2)">《服务协议》</span>和
            <span class="key-link" onclick="core.news(1)">《用户隐私协议》</span>。</div>
        
    </div>
    <div class="btn  btn-orange" tapmode="highlight" onclick="fnLogin();">登录</div>
    <div style="margin-top: 50px;" tapmode="highlight" onclick="reg();">还没有账号？ <span class="key-link"> 现在注册 </span></div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script src="../script/common.js"></script>
<script type="text/javascript">
    apiready = function () {

        console.log(api.frameName);

        console.log(api.winName);


    };

    var UIInput;
    var usernameUIInputId;
    var passwordUIInputId;
    var usernameValue;
    var passwordValue;

    // 登录
    async function fnLogin() {
        var dom = document.querySelector("#agree");
        if (!dom.checked) {
            core.toast('请同意注册协议.');
            return;
        }
        usernameValue = document.getElementById("username").value;
        passwordValue = document.getElementById("password").value;
        console.log(usernameValue);
        console.log(passwordValue);
        var dt = {
            "username": usernameValue,
            "password": passwordValue
        };
        if (dt.username.length < 11) {
            core.toast("用户名必需是11位手机号");
            return;
        }
        if (dt.password.length < 3) {
            core.toast("用户名不能少于3位");
            return;
        }
        let res = await core.post("api/tuser/loginpass", dt,);
        if (res.code == 200) {
            $api.setStorage('userinfo', res.data);
            
            api.alert({
                title: '提示',
                msg: '登录成功',
            }, function (ret, err) {
                api.rebootApp();
                core.initUser();  // 调用user页面的initUser方法
                api.closeWin();
            
            });
        } else {
            api.toast({
                msg: '登录失败，用户名或密码错误',
                duration: 2000,
                location: 'middle'
            });
        }
       
    }

    // 被注册页面调用，用于从注册页面传递用户名
    function fnSetUsername(username_) {
        usernameValue = username_;

    }

    function toBack() {
        core.back();
    }

    function reg() {
        api.openWin({
            name: 'reg',
            url: './userreg.html',
            pageParam: {
                //    index: param
            }
        })
        core.back();

    }
</script>

</html>